#include<bits/stdc++.h>
using namespace std;
char _be;
const int mod = 1000000007;
int f[311][1<<18|1],g[2][1<<18|1];
int a[311][311],suf[311][311],pre[311][311];
int dui[311][311],idx;
int n,m;
bool flag;
int ans[311][311];
bool Check(int S,int i,int j)
{
	return ((S & pre[i][j - 1] & suf[i][j + 1]) == S);
}
char _ed;
int main()
{
	double be = clock();
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("disanti.in","r",stdin);
	freopen("disanti.out","w",stdout);
	cin >> n >> m;
	if(n < m)
		flag = 1;
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= m;j++)
		{
			int x;char c;
			cin >> c;
			x = c - '0';
			if(flag)
				a[j][i] = x;
			else
				a[i][j] = x;
		}
	}
	if(flag)
		swap(n,m);
	for(int i = 1;i <= n;i++)
		a[i][0] = a[i][m + 1] = -1;
	for(int i = 1;i <= m;i++)
		a[0][i] = a[n + 1][i] = -1;
	for(int i = 1;i <= n;i++)
	{
		pre[i][0] = (1 << m + 1) - 1;
		for(int j = 1;j <= m;j++)
		{
			pre[i][j] = pre[i][j - 1];
			if(a[i][j] != a[i + 1][j])
				pre[i][j] ^= (1 << j - 1);
		}
		suf[i][m + 1] = (1 << m + 1) - 1;
		for(int j = m;j;j--)
		{
			suf[i][j] = suf[i][j + 1];
			if(a[i][j] != a[i - 1][j])
				suf[i][j] ^= (1 << j);
		}
	}
	f[0][0] = 1;
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= m;j++)
		{
			dui[i][j] = ++idx;
			// int nw = idx,lst = idx - 1;
			int opl = (1 << j - 1),opu = (1 << j),opd = opl,opr = opu;
			for(int S = 0;S < (1 << m + 1);S++)
			{
				int l = S & opl,u = S & opu;
				if(l && u)
					continue;
				if(l && a[i][j] == a[i][j - 1])
				{
					int T = S ^ opl;
					(f[idx][T] += f[idx - 1][S]) %= mod;
					T ^= opr;
					(f[idx][T] += f[idx - 1][S]) %= mod;
				}
				if(u && a[i][j] == a[i - 1][j])
				{
					int T = S ^ opu;
					(f[idx][T] += f[idx - 1][S]) %= mod;
					T ^= opd;
					(f[idx][T] += f[idx - 1][S]) %= mod;
				}
				if(!l && !u)
				{
					int T = S;
					(f[idx][T] += f[idx - 1][S]) %= mod;
					T ^= opd;
					(f[idx][T] += f[idx - 1][S]) %= mod;
					T ^= opd ^ opr;
					(f[idx][T] += f[idx - 1][S]) %= mod;
				}
			}
		}
		for(int S = 0;S < (1 << m + 1);S++)
		{
			if(S & (1 << m))
				continue;
			(g[0][S << 1] += f[idx][S]) %= mod;
		}
		memcpy(f[idx],g[0],sizeof(f[idx]));
		memset(g[0],0,sizeof(g[0]));
	}
	g[0][0] = 1;
	int nw = 0,lst = 1;
	for(int i = n;i;i--)
	{
		for(int j = m;j;j--)
		{
			swap(nw,lst);
			memset(g[nw],0,sizeof(g[nw]));
			int id = dui[i][j];
			//Solve ans:
			a[i][j] ^= 1;
			int opl = (1 << j - 1),opu = (1 << j),opd = opl,opr = opu;
			for(int S = 0;S < (1 << m + 1);S++) if(Check(S,i,j))
			{
				int l = S & opl,u = S & opu;
				if(l && u)
					continue;
				if(l && a[i][j] == a[i][j - 1])
				{
					int T = S ^ opl;
					(ans[i][j] += 1ll * f[id - 1][S] * g[lst][T] % mod) %= mod;
					if(a[i][j] == a[i][j + 1])
					{
						T ^= opr;
						(ans[i][j] += 1ll * f[id - 1][S] * g[lst][T] % mod) %= mod;
					}
				}
				if(u && a[i][j] == a[i - 1][j])
				{
					int T = S ^ opu;
					(ans[i][j] += 1ll * f[id - 1][S] * g[lst][T] % mod) %= mod;
					if(a[i][j] == a[i + 1][j])
					{
						T ^= opd;
						(ans[i][j] += 1ll * f[id - 1][S] * g[lst][T] % mod) %= mod;
					}
				}
				if(!l && !u)
				{
					int T = S;
					(ans[i][j] += 1ll * f[id - 1][S] * g[lst][T] % mod) %= mod;
					T ^= opd;
					if(a[i][j] == a[i + 1][j])
						(ans[i][j] += 1ll * f[id - 1][S] * g[lst][T] % mod) %= mod;
					T ^= opd ^ opr;
					if(a[i][j] == a[i][j + 1])
						(ans[i][j] += 1ll * f[id - 1][S] * g[lst][T] % mod) %= mod;
				}
			}
			a[i][j] ^= 1;

			//Solve g:
			for(int S = 0;S < (1 << m + 1);S++)
			{
				int r = S & opr,d = S & opd;
				if(r && d)
					continue;
				if(r && a[i][j] == a[i][j + 1])
				{
					int T = S ^ opr;
					(g[nw][T] += g[lst][S]) %= mod;
					T ^= opl;
					(g[nw][T] += g[lst][S]) %= mod;
				}
				if(d && a[i][j] == a[i + 1][j])
				{
					int T = S ^ opd;
					(g[nw][T] += g[lst][S]) %= mod;
					T ^= opu;
					(g[nw][T] += g[lst][S]) %= mod;
				}
				if(!r && !d)
				{
					int T = S;
					(g[nw][T] += g[lst][S]) %= mod;
					T ^= opu;
					(g[nw][T] += g[lst][S]) %= mod;
					T ^= opu ^ opl;
					(g[nw][T] += g[lst][S]) %= mod;
				}
			}
		}
		swap(nw,lst);
		memset(g[nw],0,sizeof(g[nw]));
		for(int S = 0;S < (1 << m + 1);S++)
		{
			if(S & 1)
				continue;
			(g[nw][S >> 1] += g[lst][S]) %= mod;
		}
	}
	if(flag)
		swap(n,m);
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= m;j++)
		{
			if(flag)
				cout << ans[j][i] << " ";
			else
				cout << ans[i][j] << " ";
		}
		cout << "\n";
	}
	cerr << "Time: " << (clock() - be) / CLOCKS_PER_SEC << "sec Memory: " << ((&_be) - (&_ed)) / 1024.0 / 1024.0 << "MB" << endl;
	return 0;
}
//我有一个绝妙的做法，但是时间太紧，写不完了